<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.utils.TranType"%>
<%@page import="com.sinba.common.system.dto.RuleDTO"%>
<%@page import="com.sinba.common.system.service.IRuleService"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.dto.ExtractDTO"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.system.service.IExtractService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.sinba.common.user.entity.Account"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
	if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/cashBusiness.jsp");
	return;
	}
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	
	ExtractDTO qdto = new ExtractDTO(); 
	qdto.setLoginName((String)session.getAttribute("loginName"));
	qdto.setParentAccount((String)session.getAttribute("loginName"));
	IExtractService extractService = (IExtractService)ac.getBean("extractService");
	int pages = 1;
	if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
		pages = Integer.parseInt(request.getParameter("pages"));
	}
	int rows = 10;
	int start = ( pages - 1 ) * rows;
	PageDTO pageDTO = extractService.findPager(qdto,start,rows,"desc","createTime");
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
	request.setAttribute("pageDTO",pageDTO);
	session.setAttribute("middle", "财务管理");
	session.setAttribute("end", "账户提现");
	
	
	//可提现余额
	ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
	Double txbalance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),TranType.DYNAMIC);
	
	request.setAttribute("txbalance1",txbalance1);
	
	
	Double txbalance2 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),TranType.STATIC);
	
	request.setAttribute("txbalance2",txbalance2);
	
	Double txbalance3 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),TranType.SIGNIN);
	
	request.setAttribute("txbalance3",txbalance3);
	
	IRuleService ruleService = (IRuleService)ac.getBean("ruleService");
	RuleDTO ruleDTO = ruleService.findRuleInfo();
	request.setAttribute("ruleDTO",ruleDTO);
	
	
	//提现封顶
	Double statAllTiXing = extractService.statAllTiXing(session.getAttribute("loginName").toString());
	request.setAttribute("statAllTiXing",statAllTiXing);
	//已提现
	IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
	Long tiXingTop = registerUserService.tiXingTop(session.getAttribute("loginName").toString());
	request.setAttribute("tiXingTop",tiXingTop);
	
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.txYeWu"/>-<fmt:message key="i18n.title"/></title>
<link rel="shortcut icon" href="../index/favicon.png" />
<jsp:include page="common.jsp"></jsp:include>
</head>
<body>
<jsp:include page="page_head.jsp"></jsp:include>
<div class="row">
	<div class="col-md-12">
		<div class="box border primary">
			<div class="box-title">
				<h4><i class="fa fa-bars"></i>账户提现</h4>
			</div>
			<div class="box-body big">
				<h3 class="form-title">
					<c:if test="${not empty ruleDTO.rule010}">
						<fmt:message key="i18n.zhuyi"/>：${ruleDTO.rule010 }
					</c:if>
					<span style="color: red;">股票钱包提现封顶：${tiXingTop},已提现：${statAllTiXing}</span>
				</h3>
				<form class="form-horizontal" role="form" id="cashBusinessForm" action="registerUser!userOpt.action" method="post" onsubmit="return checkform();" >
					<input type="hidden" name="optType" value="TingXiangApply" />
					<input type="hidden" name="extractDTO.loginName" value="${session.loginName }" />
					<input type="hidden" name="pageUrl" value="cashBusiness.jsp" />
					<input type="hidden" value="${txbalance1 }" id="cashbussiness_balance1" />
					<input type="hidden" value="${txbalance2 }" id="cashbussiness_balance2" />
					<input type="hidden" value="${txbalance3 }" id="cashbussiness_balance3" />
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.dyBalance"/>：</label>
					<div class="col-sm-9">
					  <input type="text" class="form-control" value="${txbalance1}" readonly="readonly" />
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.dyBalance"/>：</label>
					<div class="col-sm-9">
					  <input type="text" class="form-control" value="${txbalance2}" readonly="readonly" />
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label">签到红包：</label>
					<div class="col-sm-9">
					  <input type="text" class="form-control" value="${txbalance3}" readonly="readonly" />
					</div>
				  </div>
				   <div class="form-group">
						<label class="col-sm-3 control-label"><fmt:message key="i18n.txAccount"/>：</label>
						<div class="col-sm-9">
						 <select class="form-control" id="dtype" name="extractDTO.dtype" >
						  	<option value="Dynamic"><fmt:message key="i18n.dyAccount"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
							<option value="Static"><fmt:message key="i18n.jtAccount"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
							<option value="SignIn">签到红包&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
						</select>
					  </div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.txMoney"/>：</label>
					<div class="col-sm-9">
					  <input type="text" required="true" class="form-control easyui-numberbox col-sm-6" name="extractDTO.tixiangSum" id="extractMoney" validType="number" />
					  <span style="color: red; display: none;" class="col-sm-5"><fmt:message key="i18n.toRmb"/>(RMB):</span>
				   </div>
				  </div>
				   <div class="form-group">
					<label class="col-sm-3 control-label"></label>
					<div class="col-sm-4">
					  <c:if test="${not empty session.activationTime}">
					  	<button type="submit" class="btn btn-primary" style="width:15em;"><fmt:message key="i18n.txApply"/></button>
					  </c:if>
					</div>
				  </div>
				 </form>
			</div>
		</div>
	</div>
</div>
<!-- ROW 3 -->
<div class="row">
	<div class="col-md-12">
		<div class="box border primary">
			<div class="box-title">
				<h4>
					<i class="fa fa-columns"></i> <span
						class="hidden-inline-mobile"><span>账户提现</span>
				</h4>
			</div>
			<div class="box-body">
				<div class="tabbable">
					<ul class="nav nav-tabs">
						<li class="active"><a href="#cashBusiness_money"
							data-toggle="tab"><i class="fa fa-signal"></i> <span
								class="hidden-inline-mobile">账户提现</span></a></li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="cashBusiness_money">
							<table
								class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th><fmt:message key="i18n.userbianhao"/></th>
					       				<th><fmt:message key="i18n.txMoney"/></th>
					       				<th><fmt:message key="i18n.applyDate"/></th>
					       				<th><fmt:message key="i18n.acceptDate"/></th>
					       				<th><fmt:message key="i18n.acceptStatus"/></th>
					       				<th><fmt:message key="i18n.remark"/></th>
									</tr>
								</thead>
								<tbody>
								<c:if test="${pageDTO.totalSize eq 0}">
									<tr><td colspan="10" align="center"><fmt:message key="i18n.noData"/></td></tr>
									</c:if>	
									<c:if test="${pageDTO.totalSize ne 0}">
										<c:forEach items="${pageDTO.data}" var="data">
										<tr>
											<td>${data.loginName }</td>
											<td>${data.tixiangSum }</td>
											
											<td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
											<td><fmt:formatDate value="${data.handTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
											<td>${data.status}</td>
											<!--  
											<td>${data.accountType}</td>
											<td>${data.bankAccount}</td>
											<td>${data.accountName}</td>
											<td>${data.openBankAddress}</td>-->
											<td>
											${data.formAccountStr}(${data.remark})
											</td>
										</tr>
										</c:forEach>
									</c:if>  
									<tr>
											<td colspan="6" style="text-align: right;">
											<a style="color: blue;" href="${pageUrl }&pages=1"><fmt:message key="i18n.firstPage"/></a>
											<c:if test="${pageDTO.page > 1}">
												<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a>
											</c:if>
											<a>${pageDTO.page}/${pageDTO.total}</a>
											<c:if test="${pageDTO.page+1<=pageDTO.total}">
												<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a>
											</c:if>
											<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a>
											<a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a>
											</td>
										</tr>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- /ROW3 -->
<jsp:include page="page_foot.jsp"></jsp:include>
<script>
$(function(){
	var _result = '${param.result}';
	if(_result=='TixiangSumGeBalance'){
		alert('T提现金额大于可提现金额!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='ApplyLoginNameNotExist'){
		alert('申请的会员不存在!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='Success'){
		alert('申请成功，财务会尽快受理!');
		window.location.href="cashBusiness.jsp";
	}
})

function changeRmb(){
	//$('#changeRmb').text($('#extractMoney').val()*4);
}


function checkform(){
	//alert('此期间与英国本部进行财务对接，不允许提现，详情请查看公告!');
	//return false;
	/* if($('#cashBusiness_validCode').val()==null || $('#cashBusiness_validCode').val()==''){
		alert('Please input the valid code(请输入验证码)!');
		return false;
	}
	 */
	var extractMoney = $('#extractMoney').val();
	if(extractMoney==null || extractMoney==''){
		alert('请输入提现金额!');
		return false;
	}
	if(extractMoney % 100 != 0){
		alert('请输入100的倍数提现金额!');
		return false;
	}
	if(extractMoney < 100){
		alert('最低提现100以上!');
		return false;
	}
	
/* 	if($('#passwordAnswer').val()==''){
		alert('密保答案不能为空!');
		$('#passwordAnswer').focus();
		return false;
	} */
	if($('#dtype').val()=='Dynamic' &&  parseFloat($('#cashbussiness_balance1').val())<parseFloat($('#extractMoney').val())){
		 alert('提取失败,可提取金额超出!');
		 return false;
	}
	if($('#dtype').val()=='Static' &&  parseFloat($('#cashbussiness_balance2').val())<parseFloat($('#extractMoney').val())){
		 alert('提取失败,可提取金额超出!');
		 return false;
	}
	if($('#dtype').val()=='SignIn' &&  parseFloat($('#cashbussiness_balance3').val())<parseFloat($('#extractMoney').val())){
		 alert('提取失败,可提取金额超出!');
		 return false;
	}
	
	/* $.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=提现&dto.activationCode='+$('#cashBusiness_validCode').val(),function(res){
		 if(!res){
			 alert('E-mail verification code is not correct(邮箱验证码不正确)!');
			 return false;
		 }else{
			 $('#cashBusinessForm').submit();
		 }
	}); */
}

</script>


</body>
</html>